package com.q.tqb.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.q.tqb.R;
import com.q.tqb.model.MineCardInfo;
import com.q.tqb.model.MoneyDetailInfo;
import com.q.tqb.util.StringUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MoneyDetailAdapter extends RecyclerView.Adapter<MoneyDetailAdapter.ViewHolder> {

    private ArrayList<MoneyDetailInfo> moneyDetailInfos;
    private Context mContext;


    public MoneyDetailAdapter(Context context, ArrayList<MoneyDetailInfo> moneyDetailInfos) {
        this.moneyDetailInfos = moneyDetailInfos;
        this.mContext = context;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_money_detail, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        MoneyDetailInfo moneyDetailInfo = moneyDetailInfos.get(position);

        holder.mTvContent.setText(moneyDetailInfo.getRemark());
        holder.mTvTime.setText(moneyDetailInfo.getPay_time());

        holder.mTvMoney.setText(moneyDetailInfo.getInout_type() + moneyDetailInfo.getMoney());

        if ("-".equals(moneyDetailInfo.getInout_type())) {
            holder.mTvMoney.setTextColor(ContextCompat.getColor(mContext, R.color.color_main));
        } else {
            holder.mTvMoney.setTextColor(ContextCompat.getColor(mContext, R.color.color_green));
        }



    }

    @Override
    public int getItemCount() {
        return moneyDetailInfos.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.tv_content)
        TextView mTvContent;
        @BindView(R.id.tv_time)
        TextView mTvTime;
        @BindView(R.id.tv_money)
        TextView mTvMoney;


        ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}